<extend name="Public/base" />
<block name="head">

<link href="__STATIC__/ztree/css/zTreeStyle/zTreeStyle.css"
	rel="stylesheet" type="text/css">
	
</block>
<block name="body">
<ul class="breadcrumb">
	<li><a href="javascript:history.back(-1)">返回上一页</a> <span
		class="divider">/</span></li>
	<li class="active">{$meta_title}</li>
</ul>
<div class="row-fluid">
	<form class="form-horizontal" action="{:U('auth')}">
		<input type="hidden" name="uid" value="{$info.uid|default=''}">
		<div class="control-group">
			<label class="control-label" for="title">权限分配</label>
			<div class="controls">
			<ul id="authtree" class="ztree"></ul>
			</div>
		</div>
		

		<div class="control-group">
			<div class="controls">
				<button type="button" class="btn"
					target-form="form-horizontal" onclick="getTreeCheck()">授权</button>
				<button type="button" class="btn"
					onclick="javascript:history.back(-1)">取消</button>
			</div>
		</div>
	</form>
	
	
	
</div>
</block>
<block name="script"> 
<script type="text/javascript"
	src="__STATIC__/ztree/js/jquery.ztree.core-3.5.min.js"></script> 
	<script type="text/javascript"
	src="__STATIC__/ztree/js/jquery.ztree.excheck-3.5.min.js"></script> 
 <script type="text/javascript">
	var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes ={$Auth};
		
	
		
		$(document).ready(function(){
			$.fn.zTree.init($("#authtree"), setting, zNodes);

		});
	

		function getTreeCheck(){
			var str='';
			var treeObj = $.fn.zTree.getZTreeObj("authtree");
			var nodes = treeObj.getCheckedNodes(true);
			for(var i = 0, l = nodes.length; i < l; i++) {
				str+=nodes[i].id;
				if(i!=l-1)
				{
					str+=",";
				}
			}

            	target ='{:U('auth')}' ;
    
			$.post(target,'auth='+str+'&uid='+{$info.uid}).success(function(data){
                if (data.status==1) {
                    if (data.url) {
                        updateAlert(data.info + ' 页面即将自动跳转~','alert-success');
                    }else{
                        updateAlert(data.info ,'alert-success');
                    }
                    setTimeout(function(){
                        if (data.url) {
                            location.href=data.url;
                        }else if( $(that).hasClass('no-refresh')){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        }else{
                            location.reload();
                        }
                    },1500);
                }else{
                    updateAlert(data.info);
                    setTimeout(function(){
                        if (data.url) {
                            location.href=data.url;
                        }else{
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        }
                    },1500);
                }
            });
			
		}
  </script> </block>
